<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- SECTION: Specifications -->
<head>
	<title>CUPS Design Description</title>
	<link rel="STYLESHEET" type="text/css" href="../cups-printable.css">
</head>
<body>

<h1 class="title">CUPS Design Description</h1>

<p>This design description documents the overall organization of CUPS. The purpose is not to provide a line-by-line description of the CUPS source code, but rather to describe the overall architecture and location of key pieces so that developers can more easily understand the underlying operation of CUPS.</p>

<h2 class="title" id="INTRO">Introduction</h2>

<p>Like most printing systems, CUPS is designed around a central print scheduling process that dispatches print jobs, processes administrative commands, provides printer status information to local and remote programs, and informs users as needed. <a href="#FIGURE1">Figure 1</a> shows the basic organization of CUPS.</p>

<h3>Scheduler</h3>

<p>The scheduler is a HTTP/1.1 and IPP/2.1 server application that manages HTTP and IPP requests, printers, classes, jobs, subscriptions, and notifications on the system. HTTP is used for normal web browser services as well as IPP operation messages passed via HTTP POST requests with the <CODE>application/ipp</CODE> content type. The scheduler uses a series of helper applications based on the Common Gateway Interface ("CGI") to provide dynamic web interfaces and can be configured to run additional site-specific programs or scripts for the web interface.</p>

<p>The scheduler is designed as a traditional single-threaded server process which runs external processes to do longer-term operations such as printing, notification, device/driver enumeration, and remote printer monitoring. External processes are normally run as a non-privileged account ("lp") and, on some platforms, with additional restrictions that limit what the processes are allowed to do.</p>

<p>The maximum number of simultaneous clients and print jobs that can be supported is primarily limited by the available server memory, file descriptors, and CPU - the scheduler itself imposes no hard limits.</p>

<div class="figure"><table summary="CUPS Block Diagram">
<caption>Figure 1: <a name="FIGURE1">CUPS Block Diagram</a></caption>
<tr><td align="center"><img src="../images/cups-block-diagram.png"
width="768" height="768" alt="CUPS Block Diagram"></td></tr>
</table></div>

<h4>Config Files</h4>

<p>The scheduler uses several configuration files to store the server settings (<a href="man-cupsd.conf.html">cupsd.conf</a>), available classes (<a href="man-classes.conf.html">classes.conf</a>), available printers (<a href="man-printers.conf.html">printers.conf</a>), current notification subscriptions (<a href="man-subscriptions.conf.html">subscriptions.conf</a>), and supported file types and filters (<a href="man-mime.types.html">mime.types</a>, <a href="man-mime.convs.html">mime.convs</a>). In addition, PostScript Printer Description ("PPD") files are associated with each printer, and the scheduler has cache files for remote printers, PPD files, and current jobs to optimize the scheduler's startup speed and availability.</p>

<h4>Job Files</h4>

<p>The scheduler stores job files in a <em>spool directory</em>, typically <var>/var/spool/cups</var>. Two types of files will be found in the spool directory: <em>control files</em> starting with the letter "c" ("c00001", "c99999", "c100000", etc.) and <em>data files</em> starting with the letter "d" ("d00001-001", "d99999-001", "d100000-001", etc.) Control files are IPP messages based on the original IPP Print-Job or Create-Job messages, while data files are the original print files that were submitted for printing. There is one control file for every job known to the system and 0 or more data files for each job.

<p>Control files are normally cleaned out after the 500th job is submitted, while data files are removed immediately after a job has successfully printed. Both behaviors can be configured.</p>

<h4>Log Files</h4>

<p>The scheduler keeps three kinds of log files which are normally stored in the <var>/var/log/cups</var> directory. The <a href="man-cupsd-logs.html">access_log</a> file lists every HTTP and IPP request that is processed by the scheduler. The <a href="man-cupsd-logs.html">error_log</a> file contains messages from the scheduler and its helper applications that can be used
to track down problems. The <a href="man-cupsd-logs.html">page_log</a> file lists every page that is printed, allowing for simple print accounting.</p>

<p>Log files are rotated automatically by the scheduler when they reach the configured size limit, by default 1MB. If the limit is set to 0 then no rotation is performed in the scheduler - this mode is often used by Linux distributions so they can use the <b>logrotated(8)</b> program to rotate them instead.</p>

<h3>Berkeley Commands</h3>

<p>CUPS provides the Berkeley <a href="man-lpc.html">lpc(8)</a>, <a href="man-lpq.html">lpq(1)</a>, <a href="man-lpr.html">lpr(1)</a>, and <a href="man-lprm.html">lprm(1)</a> commands. In general, they function identically to the original Berkeley commands with the following exceptions:</p>

<ol>
  <li>The <b>lpc</b> command currently only supports the "status" sub-command.</li>
  <li>The <b>lpr</b> command does not support the format modifier options "1" (TROFF font set 1), "2" (TROFF font set 2), "3" (TROFF font set 3), "4" (TROFF font set 4), "c" (CIFPLOT), "d" (DVI), "f" (FORTRAN), "g" (GNU plot), "i" (indentation), "n" (Ditroff), "r" (Sun raster), "t" (Troff), or "w" (width), as they do not map to the IPP MIME media type based document formats.</li>
</ol>

<h3>System V Commands</h3>

<p>CUPS provides the System V <a href="man-cancel.html">cancel(1)</a>, <a href="man-lp.html">lp(1)</a>, <a href="man-lpadmin.html">lpadmin(8)</a>, <a href="man-lpmove.html">lpmove(8)</a>, and <a href="man-lpstat.html">lpstat(1)</a> commands. In general, they function identically to the original System V commands with the following exceptions:</p>

<ol>
  <li>All commands may ask for a password; the System V print spooler requires root access to perform administration tasks, while CUPS allows for more flexible configurations.</li>
  <li>The <b>lpadmin</b> command does not implement the Solaris "-A" (alert), "-F" (fault recovery), "-M" (mount  form/wheel), "-P" (paper list), "-S" (print wheels), "-T" (type list), "-U" (dialer info), "-W" (wait), "-f" (form name), "-l" (content-type list), "-s" (remote printer), or "-t" (number of trays) options.</li>
</ol>

<h3>CUPS Commands</h3>

<p>CUPS provides the <a href="man-cupsaccept.html">cupsaccept(8)</a>, <a href="man-cupsenable.html">cupsdisable(8)</a>, <a href="man-cupsenable.html">cupsenable(8)</a>, <a href="man-cupsaccept.html">cupsreject(8)</a>, <a href="man-cupstestppd.html">cupstestppd(1)</a>, and <a href="man-lpinfo.html">lpinfo(8)</a> commands. The <b>cupsaccept</b>, <b>cupsdisable</b>, <b>cupsenable</b>, and <b>cupsreject</b> commands correspond to the System V <b>accept</b>, <b>disable</b>, <b>enable</b>, and <b>reject</b> commands but have been renamed to avoid confusion and conflicts with the <b>bash(1)</b> internal <b>enable</b> command of the same name.</p>

<h3>LPD Support</h3>

<p>LPD client support is provided via the <a href="man-cups-lpd.html">cups-lpd(8)</a> program. Incoming LPD requests are accepted on TCP port 515 by the local <b>inetd(8)</b>, <b>launchd(8)</b>, or <b>xinetd(8)</b> process and forwarded to the <b>cups-lpd</b> program for conversion to the corresponding IPP request(s).</p>

<p>The <b>cups-lpd</b> program conforms, for the most part, to RFC 1179: Line Printer Daemon Protocol, but does not enforce the privileged source port restriction specified in that document. In addition, the banner page and output format options are usually overridden via command-line options to the <b>cups-lpd</b> program when it is invoked by the corresponding super-daemon program.</p>

<h3>Web Interface</h3>

<p>The web interface is supported by five CGI programs. <a href="#TABLE1">Table 1</a> describes the purpose of each of the programs.</p>

<div class="table"><table summary="CGI Programs">
  <caption>Table 1: <a name="TABLE1">CGI Programs</a></caption>
  <thead>
    <tr>
      <th>Program</th>
      <th>Location</th>
      <th>Description</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>admin.cgi</td>
      <td>/admin</td>
      <td>Provides all of the administrative functions</td>
    </tr>
    <tr>
      <td>classes.cgi</td>
      <td>/classes</td>
      <td>Lists classes and provides class management functions</td>
    </tr>
    <tr>
      <td>help.cgi</td>
      <td>/help</td>
      <td>Provides access to online help documents</td>
    </tr>
    <tr>
      <td>jobs.cgi</td>
      <td>/jobs</td>
      <td>Lists jobs and provides job management functions</td>
    </tr>
    <tr>
      <td>printers.cgi</td>
      <td>/printers</td>
      <td>Lists printers and provides printer management functions</td>
    </tr>
  </tbody>
</table></div>

<h3>Notifiers</h3>

<p>Notifiers (<a href="man-notifier.html">notifier(7)</a>) provide the means for sending asynchronous event notifications from the scheduler. Notifiers are executed with the recipient information on the command-line and the event data on the standard input. For example:</p>

<pre class="command">
CUPS_SERVERBIN/notifier/foo recipient user-data
</pre>

<p>CUPS includes two notifiers: <b>mailto</b> to provide SMTP-based email notifications and <b>rss</b> to provide Really Simple Syndication ("RSS") notifications from the scheduler. Additional notifiers can be installed in the <var>notifier</var> directory as needed to support other methods.</p>

<h3>Filters</h3>

<p>Filters (<a href="man-filter.html">filter(7)</a>) convert job files into a printable format. Multiple filters are run, as needed, to convert from the job file format to the printable format. A filter program reads from the standard input or from a file if a filename is supplied. All filters must support a common set of options including printer name, job ID, username, job title, number of copies, and job options. All output is sent to the standard output.</p>

<p>CUPS provides filters for printing text, PostScript, PDF, HP-GL/2, and many types of image files. CUPS also provides printer driver filters for HP-PCL, ESC/P, and several types of label printers. Additional filters can be registered with CUPS via mime.convs and PPD files.</p>

<h3>Port Monitors</h3>

<p>Port monitors handle the device- and channel-specific data formatting for a printer. Port monitors use the same interface as filters.</p>

<p>CUPS includes two port monitors: the <b>bcp</b> port monitor which supports the PostScript Binary Communications Protocol ("BCP") and the <b>tbcp</b> port monitor which supports the PostScript Tagged Binary Communications Protocol ("TBCP"). Additional port monitors can be registered in PPD files.</p>

<h3>Backends</h3>

<p>Backends (<a href="man-backend.html">backend(7)</a>) send print data to the printer and enumerate available printers/devices as needed. Backends use the same interface as filters.</p>

<p>CUPS includes backends for AppSocket (JetDirect), IPP, LPD, and USB connections and DNS-SD and SNMP for discovery. Additional backends can be added as needed without additional configuration.</p>


<h2 class="title" id="PROGRAMMING">Programming Interfaces</h2>

<p>The CUPS library (libcups) contains all of the core HTTP and IPP communications code as well as convenience functions for queuing print jobs, getting printer information, accessing resources via HTTP and IPP, manipulating PPD files, and reading and writing raster streams. The scheduler and all commands, filters, and backends use this library.</p>

</body>
</html>
